
package com.yc.sole.erp.controller;

import com.yc.sole.erp.biz.ShiftBiz;
import com.yc.sole.erp.request.ShiftQueryReq;
import com.yc.sole.erp.request.ShiftReq;
import com.yc.sole.erp.response.ShiftResp;
import com.yc.sole.framework.mybatis.page.BaseBatchIdsReq;
import com.yc.sole.framework.mybatis.page.BasePageReq;
import com.yc.sole.framework.mybatis.page.Paging;
import com.yc.sole.framework.result.Result;
import com.yc.sole.framework.validate.DeleteGroup;
import com.yc.sole.framework.validate.SaveGroup;
import com.yc.sole.framework.validate.UpdateGroup;
import com.yc.sole.framework.web.PreAuth;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author yizuomin
 * @date 2024-01-25
 **/
@Slf4j
@RestController
@RequiredArgsConstructor
public class ShiftController {

    private final ShiftBiz shiftBiz;

    /**
     * 新增班次类型
     *
     * @param shiftReq
     * @return RestResult
     */
    @PreAuth(value = "erp:shift:save", description = "新增班次类型")
    @PostMapping("/api/erp/shift/saveShift")
    public Result<Void> saveShift(@RequestBody @Validated(SaveGroup.class) ShiftReq shiftReq) {
        shiftBiz.saveShift(shiftReq);
        return Result.success();
    }

    /**
     * 通过Id修改班次类型
     *
     * @param shiftReq
     * @return RestResult
     */
    @PreAuth(value = "erp:shift:update", description = "修改班次类型")
    @PostMapping("/api/erp/shift/updateShiftById")
    public Result<Void> updateShiftById(@RequestBody @Validated(UpdateGroup.class) ShiftReq shiftReq) {
        shiftBiz.updateShiftById(shiftReq);
        return Result.success();
    }

    /**
     * 通过id批量删除班次类型
     *
     * @param baseDeleteReq
     * @return RestResult
     */
    @PreAuth(value = "erp:shift:delete", description = "删除班次类型")
    @PostMapping("/api/erp/shift/deleteShift")
    public Result<Void> deleteShift(@RequestBody @Validated(DeleteGroup.class) BaseBatchIdsReq baseDeleteReq) {
        shiftBiz.deleteShiftByIds(baseDeleteReq.getIds());
        return Result.success();
    }

    /**
     * 根据id查询班次类型
     *
     * @param id
     * @return Result
     */
    @PreAuth(value = "erp:shift:select", description = "查询班次类型")
    @PostMapping("/api/erp/shift/selectShiftById/{id}")
    public Result<ShiftResp> selectShiftById(@PathVariable Long id) {
        return Result.data(shiftBiz.selectShiftById(id));
    }

    /**
     * 根据name查询班次类型
     *
     * @return Result
     */
    @PreAuth(value = "erp:shift:select", description = "查询班次类型")
    @PostMapping("/api/erp/shift/selectAllShift")
    public Result<List<ShiftResp>> selectAllShift() {
        return Result.data(shiftBiz.selectAllShift());
    }


    /**
     * 分页查询班次类型
     *
     * @param basePageReq
     * @return Result
     */
    @PreAuth(value = "erp:shift:select", description = "查询班次类型")
    @PostMapping("/api/erp/shift/selectShiftPage")
    public Result<Paging<ShiftResp>> selectShiftPage(@RequestBody @Validated BasePageReq<ShiftQueryReq> basePageReq) {
        return Result.data(shiftBiz.selectShiftPage(basePageReq.toPage(), basePageReq.getQuery()));
    }
}
